package com.miyake.rest;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class StreamToByteConverter {
    private InputStream stream;

    public StreamToByteConverter(InputStream is) {
        this.stream = is;
    }
    
	public byte[] get() {
		byte[] ret = null;
		try {
			int len = this.stream.available();
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
		    
	        byte[] buffer = new byte[8192];
	        while ((len = this.stream.read(buffer, 0, buffer.length)) != -1) {             
	        	baos.write(buffer, 0, len);
	        } 
	        baos.flush();
	        
	        ret = baos.toByteArray();
	        baos.close();
	        
		} catch (IOException e) {
			e.printStackTrace();
		}   

		return ret;
	}
}